<template>
	<view class="container-box bai left clearfix">
		<view class="index-box left clearfix bai">
			<zmt-header @showLeftMenu="setLeftMenu"></zmt-header>
		</view>
		<!--内容部分-->
		<view class="index-content left clearfix">
			<!--左侧菜单-->
			<view class="index-menu left clearfix" v-if="showLeftMenu==true">
				<zmt-menu @selected="navigatorTo"></zmt-menu>
			</view>
			<!--右侧内容-->
			<view class="index-contents right clearfix" :style="showLeftMenu==true?'width:calc(100% - 250px)':'width:100%;border-radius:10px;'">
				<index-home v-if="page=='home' || page=='' || page==null" :userinfo="userinfo"></index-home>
				<system-menu v-if="page=='system-menu'"></system-menu>
				<navigator-menu v-if="page =='navigator-menu'"></navigator-menu>
				<index-banner v-if="page == 'index-banner'"></index-banner>
				<!--新闻封面-->
				<news-banner v-if="page == 'news-banner'"></news-banner>
				<goods-detail v-if="page == 'goods-detail'" :userinfo="userinfo" :id="id"></goods-detail>
				<video-list v-if="page == 'video-list'" :userinfo="userinfo"></video-list>
				<goods-list v-if="page == 'goods-list'" :userinfo="userinfo" :currentPage="currentPage"></goods-list>
				<news-list v-if="page == 'news-list'"></news-list>
				<file-list v-if="page == 'file-list'"></file-list>
				<about-us v-if="page == 'about-us'" :userinfo="userinfo"></about-us>
				<terms v-if="page == 'terms'" :userinfo="userinfo"></terms>
				<contact-us v-if="page == 'contact-us'" :userinfo="userinfo"></contact-us>
				<goods-edit v-if="page == 'goods-edit'" :userinfo="userinfo" :id="id"></goods-edit>
				<goods-en-edit v-if="page == 'goods-en-edit'" :userinfo="userinfo" :id="id"></goods-en-edit>
				<goods-add v-if="page == 'goods-add'" :userinfo="userinfo"></goods-add>
				<news-add :id="id" v-if="page == 'news-add'" :userinfo="userinfo"></news-add>
				<userinfo-role-group v-if="page == 'userinfo-role-group'" :userinfo="userinfo"></userinfo-role-group>
				<userinfo-role-add v-if="page == 'userinfo-role-add'" :id="id" :userinfo="userinfo"></userinfo-role-add>
				<pay v-if="page == 'pay'" :userinfo="userinfo"></pay>
				<!--采购单添加-->
				<purchase-add v-if="page == 'purchase-add'" :id="id" :userinfo="userinfo"></purchase-add>
				<!--采购单列表-->
				<purchase-list v-if="page == 'purchase-list'" :id="id" :userinfo="userinfo"></purchase-list>
				
				<category-add :id="id" :children="children" :newAdd="newAdd" :childrenId="childrenId" v-if="page == 'category-add'" :userinfo="userinfo"></category-add>
				<category-list v-if="page == 'category-list'" :userinfo="userinfo"></category-list>
				<system-menu-add :id="id" :children="children" :newAdd="newAdd" :childrenId="childrenId" v-if="page == 'system-menu-add'"></system-menu-add>
				<userinfo-division v-if="page=='userinfo-division'" :userinfo="userinfo"></userinfo-division>
				<!--订单管理-->
				<order-list :currentPage="currentPage" v-if="page == 'order-list'" :userinfo="userinfo"></order-list>
				<wait-order :currentPage="currentPage" v-if="page == 'wait-order'" :userinfo="userinfo"></wait-order>
				<after-order :currentPage="currentPage" v-if="page == 'after-order'" :userinfo="userinfo"></after-order>
				<already-order :currentPage="currentPage" v-if="page == 'already-order'" :userinfo="userinfo"></already-order>
				<invoice-order :currentPage="currentPage" v-if="page == 'invoice-order'" :userinfo="userinfo"></invoice-order>
				<userinfo-add v-if="page == 'userinfo-add'" :id="id" :userinfo="userinfo"></userinfo-add>
				<userinfo-list :currentPage="currentPage" v-if="page == 'userinfo-list'" :userinfo="userinfo"></userinfo-list>
				<admin-list :currentPage="currentPage" v-if="page == 'admin-list'" :userinfo="userinfo"></admin-list>
				<userinfo-disable :currentPage="currentPage" v-if="page == 'userinfo-disable'" :userinfo="userinfo"></userinfo-disable>
				<!--意见反馈-->
				<opinion v-if="page=='opinion'" :userinfo="userinfo"></opinion>
			</view>
		</view>
	</view>
</template>
<style scoped>
	.index-contents{width:calc(100% - 250px);height:auto;background:#fff;border-radius: 10px;padding-bottom:50px;min-height:800px;}
	.index-menu{width:240px;height:100%;background:#fff;border-radius: 10px;position:fixed;}
	page,body{height:100%;}
	.index-content{width:100%;height:calc(100% - 90px);margin-top:65px;}
	.index-box{width:100%;min-height:55px;position:fixed;left:0;right:0;top:0;z-index:999;}
	.container-box{height:100%;}
</style>

<script>
	var db = uniCloud.database();
	export default {
		data() {
			return {
				showLeftMenu:true,
				page:'index-home',
				children:null,
				childrenId:null,
				newAdd:null,
				userinfo:{},//登录用户信息
				currentPage:1,//当前页面
				id:null
			}
		},
		created() {
			var that = this;
			//验证用户是否登录
			uni.getStorage({
				key:'userinfo-login',
				success:function(e){
					var data = e.data;
					var userinfo = data.userinfo;
					var expire = data.expire;
					var time = new Date().getTime();
					if(!userinfo || !userinfo._id || time > expire){
						db.collection('userinfo').where({_id:userinfo._id,is_admin:true}).get({getOne:true}).then(res=>{
							var userinfoData = res.result.data;
							if(!userinfoData || !userinfoData._id){
								//跳转到登录页面重新登录
								uni.redirectTo({
									url:'/pages/login/login'
								})
							}
						}).catch(err=>{
							//跳转到登录页面重新登录
							uni.redirectTo({
								url:'/pages/login/login'
							})
						});
						
					}else{
						that.userinfo = userinfo;
					}
				},
				fail() {
					uni.redirectTo({
						url:'/pages/login/login'
					})
				}
			})
		},
		onLoad(e) {
			var page = e.page;
			this.currentPage = e.p;
			this.page = page;
			this.id = e.id;
			this.children = e.children;
			this.childrenId = e.childrenId;
			this.newAdd = e.newAdd;
		},
		methods: {
			//选中菜单跳转页面
			navigatorTo(page){
				console.log('page',page);
				this.currentPage = 1;
				this.page = page.item.url;
				this.id = null
				
			},
			setLeftMenu(e){
				this.showLeftMenu = e;
			}
		}
	}
</script>


